//
//  BKCMCellDetailView.m
//  bestkeep
//
//  Created by 毛韶谦 on 2017/1/16.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKCMCellDetailView.h"
#import "BKSCCommon.h"
#import "BKCMGoodsDetailModel.h"

#define kColorDetailLabel RgbColor(64, 64, 64)
#define kColorOtherLabel [BKSCCommon fromHexValue:0x888888]

@interface BKCMCellDetailView ()

@property (nonatomic, strong) UILabel *detailLabel;  //物品详情介绍

@property (nonatomic, strong) UILabel *sendDateStr_Label;  //物品到货日期

@property (nonatomic, strong) UILabel *colorAndSize;  //颜色 尺码

@property (nonatomic, strong) UILabel *vipPrice;   //会员价  价格

@property (nonatomic, strong) UILabel *orderPrompt;   //是否单独下单提示

@property (nonatomic, strong) UIImageView *pre_SaleImageView; //预售商品图标

@end

@implementation BKCMCellDetailView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        self.userInteractionEnabled = YES;
        
        //商品名字        2016年05月27日22:14:44
        _detailLabel = [UILabel new];
        [_detailLabel setText:@"----"];
        _detailLabel.numberOfLines = 2;
        [_detailLabel setTextAlignment:NSTextAlignmentLeft];
        [_detailLabel setFont:[UIFont systemFontOfSize:14.0]];//12-14
        [_detailLabel setTextColor:kColorDetailLabel];
        [self addSubview:_detailLabel];
        
        self.orderPrompt = [[UILabel alloc] init];
        [self.orderPrompt setText:@"仅限单独下单"];
        [self.orderPrompt setTextAlignment:NSTextAlignmentLeft];
        [self.orderPrompt setFont:[UIFont systemFontOfSize:12.0f]];
        [self.orderPrompt setTextColor:BESTKEEP_RED];
        [self addSubview:self.orderPrompt];
        //到货日期        2016年06月06日18:18:39
        _sendDateStr_Label = [UILabel new];
        _sendDateStr_Label.numberOfLines = 1;
        [_sendDateStr_Label setFont:[UIFont systemFontOfSize:12.0]];
        [_sendDateStr_Label setTextColor:kColorOtherLabel];
        [_sendDateStr_Label setTextAlignment:NSTextAlignmentLeft];
        [self addSubview:_sendDateStr_Label];
        
        _pre_SaleImageView = [[UIImageView alloc] init];
        [_pre_SaleImageView setContentMode:UIViewContentModeScaleAspectFit];
        self.pre_SaleImageView.image = [UIImage imageNamed:@"icon_time_nor"];
        [self addSubview:_pre_SaleImageView];
        
        //商品描述   2016年05月27日22:15:21
        _colorAndSize = [UILabel new];
        [_colorAndSize setFont:[UIFont systemFontOfSize:12.0]];//9--11
        _colorAndSize.numberOfLines = 1;
        [_colorAndSize setTextColor:kColorOtherLabel];
        [_colorAndSize setTextAlignment:NSTextAlignmentLeft];
        [self addSubview:_colorAndSize];
        
        
        //2016年05月27日22:12:54--价格
        _vipPrice = [UILabel new];
        [_vipPrice setText:@"--"];
        [_vipPrice setTextAlignment:NSTextAlignmentLeft];
        [_vipPrice setTextColor:BESTKEEP_RED];
        [_vipPrice setFont:[UIFont systemFontOfSize:15]];//12-14
        
        [self addSubview:_vipPrice];
        
        
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left);
            make.right.mas_equalTo(self.mas_right).offset(-10);
            make.top.mas_equalTo(self.mas_top);
        }];
        
        [_pre_SaleImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(self.detailLabel.mas_left);
            make.top.mas_equalTo(self.detailLabel.mas_top).offset(0.8f);
            make.height.mas_equalTo(15);
            make.width.mas_equalTo(132.0f/45.0f*15);
        }];
        
        [_vipPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left);
            make.bottom.mas_equalTo(self.mas_bottom);
            make.height.mas_equalTo(14);
        }];
        
    }
    
    return self;
}

- (void)setCellDetail:(BKCMGoodsDetailModel *)cellDetail{
    
    if (!cellDetail.shopcart_flag) {
        self.detailLabel.textColor = [BKSCCommon fromHexValue:0xB2B2B2];
        self.sendDateStr_Label.textColor = [BKSCCommon fromHexValue:0xB2B2B2];
        self.colorAndSize.textColor = [BKSCCommon fromHexValue:0xB2B2B2];
        self.vipPrice.textColor = [BKSCCommon fromHexValue:0xB2B2B2];
        [self.orderPrompt setTextColor:[BKSCCommon fromHexValue:0xB2B2B2]];
    }else {
        self.detailLabel.textColor = kColorDetailLabel;
        self.sendDateStr_Label.textColor = kColorOtherLabel;
        self.colorAndSize.textColor = kColorOtherLabel;
        self.vipPrice.textColor = BESTKEEP_RED;
        [self.orderPrompt setTextColor:BESTKEEP_RED];
    }
    
    
    float price = [[NSString stringWithFormat:@"%@",cellDetail.member_price] floatValue];
    self.vipPrice.text = [NSString stringWithFormat:@"¥ %.2f",price];//会员价  价格
    
    if (cellDetail.sendDateStr.length) {
        self.sendDateStr_Label.text = cellDetail.sendDateStr;
        self.sendDateStr_Label.hidden = NO;
    }else {
        self.sendDateStr_Label.text = cellDetail.sendDateStr;
        self.sendDateStr_Label.hidden = YES;
    }
    
    if (cellDetail.thNormalType) {
        self.pre_SaleImageView.hidden = NO;
        self.detailLabel.text = [NSString stringWithFormat:@"             %@",cellDetail.goods_name];            //物品详情介绍
        self.sendDateStr_Label.hidden = NO;
    }else {
        self.sendDateStr_Label.hidden = YES;
        self.detailLabel.text = cellDetail.goods_name;            //物品详情介绍
        self.pre_SaleImageView.hidden = YES;
    }
    
    //更新布局
    [self reloadViewWithData:cellDetail];
}


- (void)reloadViewWithData:(BKCMGoodsDetailModel *)cellDetail {
    
    [self.orderPrompt mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-10);
        make.left.mas_equalTo(self.mas_left);
        make.height.mas_equalTo(12);
        make.top.mas_equalTo(self.detailLabel.mas_bottom).offset(4);
    }];
    [self.colorAndSize mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right).offset(-10);
        if (cellDetail.singleDeliver) {
            make.top.mas_equalTo(self.orderPrompt.mas_bottom).offset(4);
        }else {
            make.top.mas_equalTo(self.detailLabel.mas_bottom).offset(4);
        }
        make.height.mas_equalTo(12);
    }];
    [_sendDateStr_Label mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right).offset(-10);
        if (cellDetail.sale_property.length) {
            make.top.mas_equalTo(self.colorAndSize.mas_bottom).offset(4);
        }else if (cellDetail.singleDeliver) {
            make.top.mas_equalTo(self.orderPrompt.mas_bottom).offset(4);
        }else {
            make.top.mas_equalTo(self.detailLabel.mas_bottom).offset(4);
        }
        
        make.height.mas_equalTo(12);
    }];
    
    if (cellDetail.singleDeliver) {
        self.orderPrompt.hidden = NO;
    }else {
        self.orderPrompt.hidden = YES;
    }
    self.colorAndSize.text = cellDetail.sale_property;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
